package tts.controller.usrdetails;

import org.springframework.beans.factory.annotation.Autowired;

import tts.controller.RedirectAction;
import tts.dao.UsersHome;
import tts.dao.UsrDetailsHome;
import tts.model.Users;
import tts.model.UsrDetails;

public class Merge extends RedirectAction{

	//fields
	private static final long serialVersionUID = -3585168687102018194L;
	private String username;
	private UsrDetails usrDetailsIns;
	@Autowired
	private UsrDetailsHome usrDetailsHome;
	@Autowired
	private UsersHome usersHome;
	

	//get & set
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public UsrDetails getUsrDetailsIns() {
		return usrDetailsIns;
	}
	public void setUsrDetailsIns(UsrDetails usrDetailsIns) {
		this.usrDetailsIns = usrDetailsIns;
	}
	
	
	//methods
	public String merge() {
		try {
			Users user = this.usersHome.findByUsername(this.username);
			this.usrDetailsHome.edit(user, this.usrDetailsIns);
		} catch (RuntimeException e) {
			addActionError(getText("operation.failed"));
			return ERROR;
		}
		addActionMessage(getText("details.updated"));
		return SUCCESS;
	}
}